//
//  EaseInOutSegue.m
//  CardWarrior
//
//  Created by Tekka Xie on 12-4-21.
//  Copyright (c) 2012年 Tencent. All rights reserved.
//

#import "EaseInOutSegue.h"
#import "WelcomeViewController.h"

@implementation EaseInOutSegue

- (void)perform
{
    @autoreleasepool {
    NSTimeInterval delay = 0.0;
    NSTimeInterval interval = 0.5;
    
    if ([super.sourceViewController isMemberOfClass:[WelcomeViewController class]])
    {
        delay = 2.0;
        interval = 1.0;
    }
    
    [UIView animateWithDuration: 0.5  delay: delay
                        options: UIViewAnimationOptionCurveLinear
                     animations: ^(){
                         UIViewController* pViewCtrl = super.sourceViewController;
                         pViewCtrl.view.alpha = 0.0;
                     }
                     completion: nil
     ];
    
    [NSTimer scheduledTimerWithTimeInterval:interval
                                     target:self
                                   selector:@selector(timerFireMethod:)
                                   userInfo:nil
                                    repeats:NO];
    }
}

- (void)timerFireMethod:(NSTimer*)theTimer
{
    @autoreleasepool{
    UIViewController* pViewCtrl = super.destinationViewController;
    [[UIApplication sharedApplication] keyWindow].rootViewController = pViewCtrl;
    pViewCtrl.view.alpha = 0.0;

    [UIView animateWithDuration: 0.5  delay: 0.1
                        options: UIViewAnimationOptionCurveEaseIn
                     animations: ^(){
                         pViewCtrl.view.alpha = 1.0;
                     }
                     completion:nil];
    }
}


@end
